<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
    <head>
        <title>
            Simple Restful Example
        </title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script>
            <!--
            function createHttpRequest()
                {
                    try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
                    try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
                    try { return new XMLHttpRequest(); } catch(e) {}
                    
                    alert("XMLHttpRequest not supported");
                    
                    return null;
                }
            
            function getHttpRequest(url, method, async, user, passwd, callback)
                {
                    var request = createHttpRequest();
                    
                    request.onreadystatechange = function()
                        {
                            if (request.readyState == 4) 
                                callback(request);
                        };
                        
                    request.open(method, url, async, user, passwd);
                    
                    return request;
                }
            
            function restfulCall(htmlObject, url, method, data)
                {
                    var request = getHttpRequest(url, method, true, null, null,
                        function(response)
                            {
                                htmlObject.innerHTML = "Return code = " 
                                                     + response.status + " ("
                                                     + response.statusText + ")- "
                                                     + "Return Body = " 
                                                     + (response.responseText.length > 0 
                                                     ? response.responseText 
                                                     : "No body returned");
                            }
                        );

                    if (method == "POST")
                        request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    
                    request.send(data);
                }
            -->
        </script>
    </head>
    
    <body>
    
    <p onclick="restfulCall(this, '${ejwContextPath}/myRestfulHandler/this/is/a/test', 'GET', null);">
        Click Here for Get (${ejwContextPath}/myRestfulHandler/this/is/a/test)
    <p onclick="restfulCall(this, '${ejwContextPath}/myRestfulHandler/test/1/12', 'POST', 'value=This+is+a+test');">
        Click Here for Post (${ejwContextPath}/myRestfulHandler/test/1/12)
    <p onclick="restfulCall(this, '${ejwContextPath}/myRestfulHandler/test/2/22', 'PUT', 'This is a test');">
        Click Here for Put (${ejwContextPath}/myRestfulHandler/test/2/22)
    <p onclick="restfulCall(this, '${ejwContextPath}/myRestfulHandler/test/3/32', 'DELETE', null);">
        Click Here for Delete (${ejwContextPath}/myRestfulHandler/test/3/32)

	<form action="${ejwContextPath}/myRestfulHandler/1" name="form1" method="post">
		<input name="value" value="1">
		<input type="submit" value="提交 ">
	</form>
	<form action="${ejwContextPath}/myRestfulHandler/2" name="form1" method="get">
		<input name="value" value="2">
		<input type="submit" value="提交 ">
	</form>
	<form action="${ejwContextPath}/myRestfulHandler/3" name="form1" method="put">
		<input name="value" value="3">
		<input type="submit" value="提交 ">
	</form>
	<form action="${ejwContextPath}/myRestfulHandler/4" name="form1" method="delete">
		<input name="value" value="4">
		<input type="submit" value="提交 ">
	</form>
	
	
    </body>
</html>
    
